/************************************************************/
/*    include files                                         */
/************************************************************/
#include      "define.h"
#include      "cpu.h"

static Word T40msTimer=25; //Delay Time is ??;
static Byte byLampeFlag=0; 
/************************************************************/
/*   Status of P0        *       Value of byLampeFlag       */ 
/*        0xff           *              0                   */
/*        0x00           *              1                   */
/*        0xaa           *              2                   */
/*        0x55           *              3                   */
/*        0xf0           *              4                   */
/*        0x0f           *              5                   */
/************************************************************/
// Description: 40ms interrupt
void Timer1ISR_40ms(void) interrupt 3 using 2
{
   TL1 = CLOCK_40MS & 0xff;   // timer1:40ms
   TH1 = CLOCK_40MS >> 8;     // CLOCK_40MS = (65536-40000)
   TF1 = 0;
   if (T40msTimer != 0)T40msTimer--;
}

void InitialCPUIO(void)
{  P1 = 0xff;	}

void InitTimer1(void)
{
   IE = 0;   //disable all interrupt
   IP = 0x08;  // hi priority:timer1
   TMOD = 0x10;  //set timer1:mode1 16 bit
   TR1 = 1;   // start timer1
   TL1 = CLOCK_40MS & 0xff;   //timer1:40ms
   TH1 = CLOCK_40MS >> 8;
   ET1 = 1;   // ebable timer1 interrupt
   EA = 1;   //ebable all interrupt
}

void main()
{
   InitialCPUIO();
   InitTimer1();
   while(1)
   {
      if (!T40msTimer)
	  {
	    T40msTimer = 25;
		switch(byLampeFlag)
		{
		  case 0:P1=0xff;break;
		  case 1:P1=0x00;break;
		  case 2:P1=0xaa;break;
		  case 3:P1=0x55;break;
		  case 4:P1=0xf0;break;
		  case 5:P1=0x0f;break;
		  default:break;
		}
		byLampeFlag++;
		byLampeFlag=byLampeFlag%6;
	  }
   }
}
